package com.lagou.k8s.service;

import com.lagou.k8s.mapper.StudentMapper;
import com.lagou.k8s.model.StudentEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lwb
 * 2021-01-13 2021-01-13
 */
@Component
public class StudentService {

    private StudentMapper studentMapper;

    public StudentEntity getStudent(Integer id){
        return studentMapper.selectById(id);
    }

    public void delete(Integer id){
        studentMapper.deleteById(id);
    }

    public void update(Integer id, String name, Integer age){
        StudentEntity studentEntity = new StudentEntity();
        studentEntity.setId(id);
        studentEntity.setName(name);
        studentEntity.setAge(age);
        studentMapper.updateById(studentEntity);
    }

    public void save(String name, Integer age){
        StudentEntity studentEntity = new StudentEntity();
        studentEntity.setName(name);
        studentEntity.setAge(age);
        studentMapper.insert(studentEntity);
    }


    @Autowired
    public void setStudentMapper(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }
}
